package wicresoft.servicesImp.expertInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wicresoft.orm.dao.UnitUserMapper;
import wicresoft.orm.entity.ExpertBaseInfo;
import wicresoft.orm.entity.UnitUser;
import wicresoft.orm.entity.UnitUserExample;
import wicresoft.services.expertInfo.ExpertBaseInfoServices;
import wicresoft.services.expertInfo.UnitUserServices;

import java.util.List;

/**
 * Created by Administrator on 2018/3/13.
 */
@Service
public class UnitUserServicesImp implements UnitUserServices {
    @Autowired
    UnitUserMapper unitUserMapper;
    @Autowired
    ExpertBaseInfoServices expertBaseInfoServices;

    public UnitUser selectByIdCard(String idCard) throws Exception {
        ExpertBaseInfo expertBaseInfo = expertBaseInfoServices.selectByIdCard(idCard);
        if (expertBaseInfo == null) {
            return null;
        } else {
            UnitUserExample unitUserExample = new UnitUserExample();
            unitUserExample.createCriteria().andPersonIdEqualTo(expertBaseInfo.getExpertId());
            List<UnitUser> unitUserList = unitUserMapper.selectByExample(unitUserExample);
            if (unitUserList.isEmpty()) {
                return null;
            } else {
                return unitUserList.get(0);
            }
        }
    }


    public int insertSelective(UnitUser unitUser) throws Exception {
        return unitUserMapper.insertSelective(unitUser);
    }
}
